package com.nl.controller.web.bean.PDF;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfPCell;
import com.itextpdf.text.pdf.PdfPTable;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.text.pdf.draw.DottedLineSeparator;
import com.itextpdf.text.pdf.draw.LineSeparator;
import com.nl.controller.web.bean.SmsReportDetail;
import com.nl.controller.web.bean.SmsReportTotal;

import java.io.File;
import java.io.FileOutputStream;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

public class PdfReport {


    public String createPdfReport(String excelName,String type,List<String> titleList, List<SmsReportTotal> reportCountList){
        try {
            // 1.新建document对象
            Document document = new Document(PageSize.A4);// 建立一个Document对象
            SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHH24mmss");
            //String fileName = sdf.format(new Date());
            // 2.建立一个书写器(Writer)与document对象关联
            File file = new File("D:\\欢迎名片报表文件.pdf");

            file.createNewFile();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
            writer.setPageEvent(new Watermark("JSHYMP"));// 水印
            writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚

            // 3.打开文档
            document.open();
            document.addTitle("Title@PDF-Java");// 标题
            document.addAuthor("Author@l");// 作者
            document.addSubject("Subject@iText pdf sample");// 主题
            document.addKeywords("Keywords@iTextpdf");// 关键字
            document.addCreator("Creator@umiz`s");// 创建者

            // 4.向文档中添加内容
            new PdfReport().generatePDF(document,type,titleList,reportCountList);

            // 5.关闭文档
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    public String createPdfReport2(List<SmsReportDetail> reportCountList){
        try {
            // 1.新建document对象
            Document document = new Document(PageSize.A4);// 建立一个Document对象
            SimpleDateFormat sdf = new SimpleDateFormat("YYYYMMddHH24mmss");
            //String fileName = sdf.format(new Date());
            // 2.建立一个书写器(Writer)与document对象关联
            File file = new File("D:\\欢迎名片报表文件.pdf");

            file.createNewFile();
            PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream(file));
            writer.setPageEvent(new Watermark("JSHYMP"));// 水印
            writer.setPageEvent(new MyHeaderFooter());// 页眉/页脚

            // 3.打开文档
            document.open();
            document.addTitle("Title@PDF-Java");// 标题
            document.addAuthor("Author@l");// 作者
            document.addSubject("Subject@iText pdf sample");// 主题
            document.addKeywords("Keywords@iTextpdf");// 关键字
            document.addCreator("Creator@umiz`s");// 创建者

            // 4.向文档中添加内容
            new PdfReport().generatePDF2(document,reportCountList);

            // 5.关闭文档
            document.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }


    // 定义全局的字体静态变量
    private static Font titlefont;
    private static Font headfont;
    private static Font keyfont;
    private static Font textfont;
    // 最大宽度
    private static int maxWidth = 520;
    // 静态代码块
    static {
        try {
            // 不同字体（这里定义为同一种字体：包含不同字号、不同style）
            BaseFont bfChinese = BaseFont.createFont("STSong-Light", "UniGB-UCS2-H", BaseFont.NOT_EMBEDDED);
            titlefont = new Font(bfChinese, 16, Font.BOLD);
            headfont = new Font(bfChinese, 14, Font.BOLD);
            keyfont = new Font(bfChinese, 10, Font.BOLD);
            textfont = new Font(bfChinese, 10, Font.NORMAL);

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    // 生成PDF文件
    public void generatePDF(Document document,String type,List<String> titleList,List<SmsReportTotal> smsReport) throws Exception {

        // 段落
        Paragraph paragraph = new Paragraph("欢迎名片短信发送统计", titlefont);
        paragraph.setAlignment(1); //设置文字居中 0靠左   1，居中     2，靠右
        paragraph.setIndentationLeft(12); //设置左缩进
        paragraph.setIndentationRight(12); //设置右缩进
        paragraph.setFirstLineIndent(24); //设置首行缩进
        paragraph.setLeading(20f); //行间距
        paragraph.setSpacingBefore(5f); //设置段落上空白
        paragraph.setSpacingAfter(10f); //设置段落下空白

        // 直线
        Paragraph p1 = new Paragraph();
        p1.add(new Chunk(new LineSeparator()));

        // 点线
        Paragraph p2 = new Paragraph();
        p2.add(new Chunk(new DottedLineSeparator()));
//
//        // 超链接
//        Anchor anchor = new Anchor("baidu");
//        anchor.setReference("www.baidu.com");
//
//        // 定位
//        Anchor gotoP = new Anchor("goto");
//        gotoP.setReference("#top");

        // 添加图片
        //Image image = Image.getInstance("https://img-blog.csdn.net/20180801174617455?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzg0ODcxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70");
        Image image = Image.getInstance("src/main/resources/static/images/logo.png");
        image.setAlignment(Image.ALIGN_RIGHT);
        image.scalePercent(20); //依照比例缩放
        PdfPTable table = null;
        // 表格
        int titleSize = titleList.size();
        if("1".equals(type)&&titleSize == 11){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("2".equals(type)&&titleSize == 12){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("3".equals(type)&&titleSize == 14){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("短信通道号", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getSender(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }
        else if("4".equals(type)&&titleSize == 15){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90, 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("短信通道号", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getSender(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("5".equals(type)&&titleSize == 13){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("6".equals(type)&&titleSize == 14){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90 , 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("7".equals(type)&&titleSize == 14){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90 , 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("短信内容", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getContent(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("8".equals(type)&&titleSize == 15){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90,90,90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("短信内容", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getContent(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("9".equals(type)&&titleSize == 14){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90,90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区域名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));

            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("10".equals(type)&&titleSize == 15){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90, 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区域名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("11".equals(type)&&titleSize == 15){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90, 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区域名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("基站名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getStationName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("12".equals(type)&&titleSize == 16){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90 , 90, 90, 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区域名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("基站名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getStationName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("13".equals(type)&&titleSize == 12){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getStationName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }else if("14".equals(type)&&titleSize == 13){
            table = createTable(new float[] { 60, 70, 90 , 90, 90, 90 , 90,  90, 90 , 90,  90, 90, 90});
            table.addCell(createCell("地市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信拆分后的数量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("长短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("正常短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("总费用(总发送量*0.03)", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外地市短信占比", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信发送量", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("外省短信占比", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCityName(), textfont));
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongNumSplit(), textfont));
                table.addCell(createCell(smsReport.get(i).getLongPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalNum(), textfont));
                table.addCell(createCell(smsReport.get(i).getNormalPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalCount(), textfont));
                table.addCell(createCell(smsReport.get(i).getTotalFee(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCities(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherCitiesPercent(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvinces(), textfont));
                table.addCell(createCell(smsReport.get(i).getOtherProvincesPercent(), textfont));
            }
        }




        //table.addCell(createCell("美好的一天", headfont, Element.ALIGN_LEFT, 6, false));

//        table.addCell(createCell("总计", keyfont));
//        table.addCell(createCell("", textfont));
//        table.addCell(createCell("", textfont));
//        table.addCell(createCell("", textfont));
//        table.addCell(createCell(String.valueOf(totalQuantity) + "件事", textfont));
//        table.addCell(createCell("", textfont));

        document.add(paragraph);
        //document.add(anchor);
        document.add(p2);
        //document.add(gotoP);
        document.add(p1);
        document.add(table);
        document.add(image);
    }

    public void generatePDF2(Document document,List<SmsReportDetail> smsReport) throws Exception {

        // 段落
        Paragraph paragraph = new Paragraph("欢迎名片短信发送明细", titlefont);
        paragraph.setAlignment(1); //设置文字居中 0靠左   1，居中     2，靠右
        paragraph.setIndentationLeft(12); //设置左缩进
        paragraph.setIndentationRight(12); //设置右缩进
        paragraph.setFirstLineIndent(24); //设置首行缩进
        paragraph.setLeading(20f); //行间距
        paragraph.setSpacingBefore(5f); //设置段落上空白
        paragraph.setSpacingAfter(10f); //设置段落下空白

        // 直线
        Paragraph p1 = new Paragraph();
        p1.add(new Chunk(new LineSeparator()));

        // 点线
        Paragraph p2 = new Paragraph();
        p2.add(new Chunk(new DottedLineSeparator()));
//
//        // 超链接
//        Anchor anchor = new Anchor("baidu");
//        anchor.setReference("www.baidu.com");
//
//        // 定位
//        Anchor gotoP = new Anchor("goto");
//        gotoP.setReference("#top");

        // 添加图片
        //Image image = Image.getInstance("https://img-blog.csdn.net/20180801174617455?watermark/2/text/aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3dlaXhpbl8zNzg0ODcxMA==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70");
        Image image = Image.getInstance("src/main/resources/static/images/logo.png");
        image.setAlignment(Image.ALIGN_RIGHT);
        image.scalePercent(20); //依照比例缩放
        PdfPTable table = null;
        // 表格
            table = createTable(new float[] { 95, 95 , 95, 95, 95 , 95,  95, 95 , 95,  95});
            table.addCell(createCell("地市/区县", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("项目名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("区域名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("基站名称", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("用户号码", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("用户归属省", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("用户归属市", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("发送时间", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("发送状态", keyfont, Element.ALIGN_CENTER));
            table.addCell(createCell("发送内容", keyfont, Element.ALIGN_CENTER));
            for (int i = 0; i < smsReport.size(); i++) {
                table.addCell(createCell(smsReport.get(i).getCountyName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMgrName(), textfont));
                table.addCell(createCell(smsReport.get(i).getRegionName(), textfont));
                table.addCell(createCell(smsReport.get(i).getStationName(), textfont));
                table.addCell(createCell(smsReport.get(i).getMsisdn(), textfont));
                table.addCell(createCell(smsReport.get(i).getUserPlace(), textfont));
                table.addCell(createCell(smsReport.get(i).getUserCity(), textfont));
                table.addCell(createCell(smsReport.get(i).getSendTime(), textfont));
                table.addCell(createCell(smsReport.get(i).getSendStateName(), textfont));
                table.addCell(createCell(smsReport.get(i).getContent(), textfont));
            }

        document.add(paragraph);
        //document.add(anchor);
        document.add(p2);
        //document.add(gotoP);
        document.add(p1);
        document.add(table);
        document.add(image);
    }



/**------------------------创建表格单元格的方法start----------------------------*/
    /**
     * 创建单元格(指定字体)
     * @param value
     * @param font
     * @return
     */
    public PdfPCell createCell(String value, Font font) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(Element.ALIGN_CENTER);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平..）
     * @param value
     * @param font
     * @param align
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并）
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, int colspan) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平居..、单元格跨x列合并、设置单元格内边距）
     * @param value
     * @param font
     * @param align
     * @param colspan
     * @param boderFlag
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, int colspan, boolean boderFlag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setColspan(colspan);
        cell.setPhrase(new Phrase(value, font));
        cell.setPadding(3.0f);
        if (!boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(15.0f);
            cell.setPaddingBottom(8.0f);
        } else if (boderFlag) {
            cell.setBorder(0);
            cell.setPaddingTop(0.0f);
            cell.setPaddingBottom(15.0f);
        }
        return cell;
    }
    /**
     * 创建单元格（指定字体、水平..、边框宽度：0表示无边框、内边距）
     * @param value
     * @param font
     * @param align
     * @param borderWidth
     * @param paddingSize
     * @param flag
     * @return
     */
    public PdfPCell createCell(String value, Font font, int align, float[] borderWidth, float[] paddingSize, boolean flag) {
        PdfPCell cell = new PdfPCell();
        cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
        cell.setHorizontalAlignment(align);
        cell.setPhrase(new Phrase(value, font));
        cell.setBorderWidthLeft(borderWidth[0]);
        cell.setBorderWidthRight(borderWidth[1]);
        cell.setBorderWidthTop(borderWidth[2]);
        cell.setBorderWidthBottom(borderWidth[3]);
        cell.setPaddingTop(paddingSize[0]);
        cell.setPaddingBottom(paddingSize[1]);
        if (flag) {
            cell.setColspan(2);
        }
        return cell;
    }
/**------------------------创建表格单元格的方法end----------------------------*/


/**--------------------------创建表格的方法start------------------- ---------*/
    /**
     * 创建默认列宽，指定列数、水平(居中、右、左)的表格
     * @param colNumber
     * @param align
     * @return
     */
    public PdfPTable createTable(int colNumber, int align) {
        PdfPTable table = new PdfPTable(colNumber);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(align);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }
    /**
     * 创建指定列宽、列数的表格
     * @param widths
     * @return
     */
    public PdfPTable createTable(float[] widths) {
        PdfPTable table = new PdfPTable(widths);
        try {
            table.setTotalWidth(maxWidth);
            table.setLockedWidth(true);
            table.setHorizontalAlignment(Element.ALIGN_CENTER);
            table.getDefaultCell().setBorder(1);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return table;
    }
    /**
     * 创建空白的表格
     * @return
     */
    public PdfPTable createBlankTable() {
        PdfPTable table = new PdfPTable(1);
        table.getDefaultCell().setBorder(0);
        table.addCell(createCell("", keyfont));
        table.setSpacingAfter(20.0f);
        table.setSpacingBefore(20.0f);
        return table;
    }
/**--------------------------创建表格的方法end------------------- ---------*/

}
